From f326023b8394296eb85a3bf2222edb1734c4cb6b Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Fri, 16 Mar 2007 10:42:25 +0000 Subject: [PATCH] xenbus: Clarify and simplify barrier usage. Signed-off-by: Keir Fraser --- .../drivers/xen/xenbus/xenbus_comms.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c index c00aaf7f6f..2521b8203d 100644 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c @@ -110,7 +110,6 @@ int xb_write(const void *data, unsigned len) /* Read indexes, then verify. */ cons = intf->req_cons; prod = intf->req_prod; - mb(); if (!check_indexes(cons, prod)) { intf->req_cons = intf->req_prod = 0; return -EIO; @@ -122,15 +121,18 @@ int xb_write(const void *data, unsigned len) if (avail > len) avail = len; + /* Must write data /after/ reading the consumer index. */ + mb(); + memcpy(dst, data, avail); data += avail; len -= avail; - /* Other side must not see new header until data is there. */ + /* Other side must not see new producer until data is there. */ wmb(); intf->req_prod += avail; - /* This implies mb() before other side sees interrupt. */ + /* Implies mb(): other side will see the updated producer. */ notify_remote_via_evtchn(xen_store_evtchn); } @@ -165,7 +167,6 @@ int xb_read(void *data, unsigned len) /* Read indexes, then verify. */ cons = intf->rsp_cons; prod = intf->rsp_prod; - mb(); if (!check_indexes(cons, prod)) { intf->rsp_cons = intf->rsp_prod = 0; return -EIO; @@ -177,7 +178,7 @@ int xb_read(void *data, unsigned len) if (avail > len) avail = len; - /* We must read header before we read data. */ + /* Must read data /after/ reading the producer index. */ rmb(); memcpy(data, src, avail); @@ -190,7 +191,7 @@ int xb_read(void *data, unsigned len) pr_debug("Finished read of %i bytes (%i to go)\n", avail, len); - /* Implies mb(): they will see new header. */ + /* Implies mb(): other side will see the updated consumer. */ notify_remote_via_evtchn(xen_store_evtchn); } -- 2.30.2